package com.z.sys.controller;

import com.github.pagehelper.PageInfo;
import com.z.sys.entity.LogoInfo;
import com.z.common.web.base.BaseController;
import com.z.common.web.vo.request.PageVo;
import com.z.common.aop.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import com.z.common.aop.enums.BusinessType;
import com.z.common.web.vo.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.z.sys.service.ILogoInfoService;
import org.springframework.web.servlet.ModelAndView;
import java.util.Arrays;

/**
 * 系统信息Controller
 *
 * @author z
 * @date 2024-01-03
 */
@Api(tags = "系统信息")
@RestController
@RequestMapping("/system/logoInfo")
public class LogoInfoController extends BaseController {

    private String prefix = "system/logoInfo";

    @Autowired
    private ILogoInfoService logoInfoService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/system/logoInfo/main','sys:logoInfo:main')")
    @ApiOperation(value = "查询页面")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询系统信息列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/logoInfo/data','sys:logoInfo:main')")
    @Log(title = "系统信息", describe = "查询系统信息列表", type = BusinessType.QUERY)
    @ApiOperation(value = "查询接口")
    public Result list(@ModelAttribute LogoInfo logoInfo, PageVo pageVo) {
        PageInfo<LogoInfo> pageInfo = logoInfoService.selectLogoInfoPage(logoInfo, pageVo);
        return Result.table(pageInfo);
    }

    /**
     * 新增系统信息
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/system/logoInfo/add','sys:logoInfo:add')")
    @ApiOperation(value = "添加页面")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增系统信息
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/system/logoInfo/save','sys:logoInfo:add')")
    @Log(title = "系统信息", describe = "新增系统信息数据", type = BusinessType.ADD)
    @ApiOperation(value = "添加接口")
    public Result save(@RequestBody LogoInfo logoInfo) {
        return Result.decide(logoInfoService.save(logoInfo));
    }

    /**
     * 修改系统信息
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/system/logoInfo/edit','sys:logoInfo:edit')")
    @ApiOperation(value = "修改页面")
    public ModelAndView edit(Long id, ModelMap map) {
        LogoInfo logoInfo =logoInfoService.getById(id);
        map.put("logoInfo", logoInfo);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改系统信息
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/system/logoInfo/update','sys:logoInfo:edit')")
    @Log(title = "系统信息", describe = "修改系统信息数据", type = BusinessType.EDIT)
    @ApiOperation(value = "修改接口")
    public Result update(@RequestBody LogoInfo logoInfo) {
        return Result.decide(logoInfoService.updateById(logoInfo));
    }

    /**
     * 删除系统信息
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/system/logoInfo/batchRemove','sys:logoInfo:del')")
    @Log(title = "系统信息", describe = "删除系统信息数据", type = BusinessType.REMOVE)
    @ApiOperation(value = "批量删除接口")
    public Result batchRemove(String ids) {
        return Result.decide(logoInfoService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 删除系统信息
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/system/logoInfo/remove','sys:logoInfo:del')")
    @Log(title = "系统信息", describe = "删除系统信息数据", type = BusinessType.REMOVE)
    @ApiOperation(value = "删除接口")
    public Result remove(@PathVariable("id") Long id) {
        return Result.decide(logoInfoService.removeById(id));
    }
}
